package com.example.service;

import com.example.entity.Course;
import com.example.entity.CourseStudent;
import com.example.exception.CustomException;
import com.example.mapper.CourseSelMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class CourseSelService {
    @Resource
    CourseSelMapper courseSelMapper;
    public void add(CourseStudent courseStudent) {
        CourseStudent courseStudent1 = courseSelMapper.selectById(courseStudent);
        if(courseStudent1 != null){
            throw new CustomException("你已经选了此课");
        }
        courseSelMapper.add(courseStudent);
    }

    public PageInfo<CourseStudent> selectAll(Integer pageNum, Integer pageSize, CourseStudent courseStudent) {
            PageHelper.startPage(pageNum,pageSize);
            List<CourseStudent> courseList=courseSelMapper.selectAll(courseStudent);
            return PageInfo.of(courseList);
        }

    public void deleteByid(Integer id) {
            courseSelMapper.deleteByid(id);
    }
}
